package com.kfm.movie;

import java.util.Objects;

public class User {

    private String username;
    private String password;
    private int role;
    private String phone;

    private Movie[] buyMovies = new Movie[10]; // 用户已购买票的信息
    private int movieCount = 0;

    public User(){}

    public User(String username, String password, int role, String phone) {
        this.username = username;
        this.password = password;
        this.role = role;
        this.phone = phone;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Movie[] getBuyMovies() {
        return buyMovies;
    }

    @Override
    public String toString() {
        return "User{" +
                "用户名：'" + username + '\'' +
                ", 密码：'" + password + '\'' +
                ", 身份：" + (role == 1 ? "管理员": "用户") +
                ", 电话：'" + phone + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return role == user.role && Objects.equals(username, user.username) && Objects.equals(password, user.password) && Objects.equals(phone, user.phone);
    }

    @Override
    public int hashCode() {
        return Objects.hash(username, password, role, phone);
    }

    public void addMovie(Movie movie) {
        // 考虑扩容
        buyMovies[movieCount ++] = movie;
    }
}
